package com.gin.no_gay_alliance.adpter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;

import com.gin.nga.response.field.SimpleUserInfo;
import com.gin.no_gay_alliance.adpter.base.BaseBindingRecyclerViewAdapter;
import com.gin.no_gay_alliance.databinding.ItemUserLinkBinding;

import java.util.List;

/**
 * 用户链接适配器
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/1 17:21
 **/
public class UserLinkAdapter extends BaseBindingRecyclerViewAdapter<ItemUserLinkBinding, UserLinkAdapter.UserInfo> implements View.OnLongClickListener {
    public UserLinkAdapter(Context context) {
        super(context);
    }

    public UserLinkAdapter(@NonNull Context context, @NonNull List<UserInfo> data) {
        super(context, data);
    }

    /**
     * 绑定数据
     *
     * @param holder
     * @param b        绑定对象
     * @param position 位置
     * @param item
     */
    @Override
    protected void onBindViewHolder(ViewHolder<ItemUserLinkBinding> holder, @NonNull ItemUserLinkBinding b, int position, UserInfo item) {
        b.getRoot().setTag(item);
        b.getRoot().init(item.userId, item.username, item.avatar, 24, 0);
        b.getRoot().setOnLongClickListener(this);
    }

    /**
     * 构造binding对象
     *
     * @param inflater
     * @return T
     */
    @NonNull
    @Override
    protected ItemUserLinkBinding buildBinding(LayoutInflater inflater) {
        return ItemUserLinkBinding.inflate(inflater);
    }

    /**
     * @return 是否应用斑马纹配色
     */
    @Override
    protected boolean useZebraStripe() {
        return false;
    }

    @Override
    public boolean onLongClick(View v) {
        return false;
    }

    public static class UserInfo {
        public Long userId;
        public String username;
        public String avatar;

        public UserInfo(SimpleUserInfo info) {
            this.userId = info.getUserId();
            this.username = info.getUsername();
        }

        public UserInfo() {
        }
    }
}
